package com.example.day10;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import java.util.List;
import java.util.Map;

public class MyAdapter extends BaseAdapter
{
    Context context;
    List<Map<String,Object>> data;
    public MyAdapter(Context context, List<Map<String,Object>> data){
        this.context=context;
        this.data=data;
    }

    @Override
    public int getCount() {
        return data.size();
    }

    @Override
    public Object getItem(int position) {
        return data.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        viewHolder vh;
        if(convertView==null){
            convertView=View.inflate(context,R.layout.item_user,null);
            vh=new viewHolder();
            vh.name=convertView.findViewById(R.id.user);
            vh.phoneNUM=convertView.findViewById(R.id.num);
            convertView.setTag(vh);
        }else{
            vh = (viewHolder)convertView.getTag();
        }
            vh.name.setText(data.get(position).get("name").toString());
            vh.phoneNUM.setText(data.get(position).get("phoneNUM").toString());

        return convertView;
    }

    private class viewHolder{
        TextView name;
        TextView phoneNUM;
    }
}
